#!/usr/bin/env python

# encoding: utf-8

'''
 * Create File task
 * Created by leixu on 2017/10/24
 * IDE PyCharm
'''
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/5/16 11:05
# @Author  : Leixu
# @Site    :
# @File    : task.py
# @Software: PyCharm Community Edition
from __future__ import absolute_import

from celery1 import app


@app.task(serializer='pickle')
def tornado_http_client(url, config):
    from http_clients.tornado_http_client import run_this_by_threading
    return run_this_by_threading(url, config)


@app.task(serializer='pickle')
def remote_script(rules, param_deliver):
    print(rules)
    print(rules._script)
    print(param_deliver)


@app.task
def add(x, y):
    return {'the value is ': str(x + y)}


@app.task
def writefile():
    out = open('/tmp/data.txt', 'w')
    out.write('hello' + '\n')
    out.close()


@app.task
def mul(x, y):
    return x * y


@app.task
def xsum(numbers):
    return sum(numbers)


if __name__ == "__main__":
    res = add.apply_async(args=[122, 34], queue='machine1', routing_key='machine1')
    print(res.get())